﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace SMS.Magus
{
    public partial class frmMovebyNum : DevExpress.XtraEditors.XtraForm
    {
        public XtraUserControl ParentControl { get; set; }
        private string opflag = "";
        public frmMovebyNum(string op)
        {
            InitializeComponent();
            this.opflag = op;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();            
        }

        private void btnMove_Click(object sender, EventArgs e)
        {
            frmAutoTel autel = (frmAutoTel)this.ParentControl;
            TextBox[] arrtb = new TextBox[10];
            arrtb[0] = txtNum2;
            arrtb[1] = txtNum3;
            arrtb[2] = txtNum4;
            arrtb[3] = txtNum5;
            arrtb[4] = txtNum6;
            arrtb[5] = txtNum7;
            arrtb[6] = txtNum8;
            arrtb[7] = txtNum9;
            arrtb[8] = txtNum10;
            arrtb[9] = txtNum11;
            for (int i = 0; i < 10; i++)
            {
                if (!autel.isnullorint(arrtb[i].Text))
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("必须是数字或者空！");
                    arrtb[i].Text = "";
                    arrtb[i].Focus();
                    return;
                }
            }
            string[] txtNum = { "1",txtNum2.Text, txtNum3.Text,txtNum4.Text,txtNum5.Text,txtNum6.Text,txtNum7.Text,txtNum8.Text,txtNum9.Text,txtNum10.Text,txtNum11.Text };
            if (opflag.Equals("up"))
            {
                if (autel.lvObjectNo.Items.Count > 0)
                {
                    foreach (ListViewItem it in autel.lvObjectNo.Items)
                    {
                        if (CompTheNo(it.Text, txtNum))
                        {   //从下移动到上方
                            autel.lvSourceNo.Items.Add(it.Text);
                            autel.lvObjectNo.Items.Remove(it);
                        }
                    }
                }
            }
            else
            {
                if (autel.lvSourceNo.Items.Count > 0)
                {
                    foreach (ListViewItem it in autel.lvSourceNo.Items)
                    {
                        if (CompTheNo(it.Text, txtNum))
                        {   //从上移动到下方
                            autel.lvObjectNo.Items.Add(it.Text);
                            autel.lvSourceNo.Items.Remove(it);
                        }
                    }
                }
            }
                
            this.Close();
        }
        /// <summary>
        /// 函数功能：判断号码是否符合数值规则
        /// 函数名称：CompTheNo(string theNo,string[] txtNum)
        /// 参    数：theNo,手机号码；txtNum,手机号码后10位数值规则
        /// 返 回 值：bool型，符合数值规则返回true,否则返回false
        /// 程 序 员：dwy_peach@msn.com
        /// 编制日期：2010-11-05
        /// 函数说明：判断号码是否符合数值规则
        /// </summary>
        public bool CompTheNo(string theNo, string[] txtNum)
        {
            for (int i = 1; i < txtNum.Length; i++)
            {
                if (txtNum[i] != "")
                {
                    if (!theNo.Substring(i, 1).Equals(txtNum[i]))
                    {
                        return false;
                    }
                }

            }
            return true;
        }

    }
}
